//
// Created by Administrator on 2021/10/21.
//

#ifndef MRenderer_MRenderer_H
#define MRenderer_MRenderer_H
#include "../core/Config.h"
#include "../utils//ShaderUtil.h"
#include "../objects/Scene.h"
#include "../gui/BaseGui.h"
#include "../gui/MainGui.h"
#include "../math/Vector2.h"

/**
 *  @param[in] pWwindow The window whose framebuffer was resized.
 *  @param[in] width The new width, in pixels, of the framebuffer.
 *  @param[in] height The new height, in pixels, of the framebuffer.
 */
static void framebuff_size_callback(GLFWwindow *window, int width, int height);
/**
 * @param[in] pWwindow The window that received the event.
 *  @param[in] key The [keyboard key](@ref keys) that was pressed or released.
 *  @param[in] scancode The system-specific scancode of the key.
 *  @param[in] action `GLFW_PRESS`, `GLFW_RELEASE` or `GLFW_REPEAT`.
 *  @param[in] mods Bit field describing which [modifier keys](@ref mods) were
 */
void key_callback(GLFWwindow *pWwindow, int,int,int,int);

/*! @brief The function signature for mouse button callbacks.
 *
 *  This is the function signature for mouse button callback functions.
 *
 *  @param[in] window The window that received the event.
 *  @param[in] button The [mouse button](@ref buttons) that was pressed or
 *  released.
 *  @param[in] action One of `GLFW_PRESS` or `GLFW_RELEASE`.
 *  @param[in] mods Bit field describing which [modifier keys](@ref mods) were
 *  held down.
 *
 *  @sa @ref input_mouse_button
 *  @sa glfwSetMouseButtonCallback
 *
 *  @since Added in version 1.0.
 *  @glfw3 Added window handle and modifier mask parameters.
 *
 *  @ingroup input
 */
void mouse_callback(GLFWwindow*,int,int,int);

class MRenderer : public Object{
private:
    /**
     * 上下文
     */
    GLFWwindow* window;
    /**
     * 场景
     */
    Scene* scene;

private:
    MRenderer();
    /**
     * 构造器
     * @param title 标题
     * @param width 宽
     * @param height 高
     */
    MRenderer(const String title = Config::WINDOW_TITLE, const int width = Config::WINDOW_WIDTH, const int height = Config::WINDOW_HEIGHT);
    /**
     * 创建window
     * */
    void createWindow();

    /**
     * 初始化窗口和场景
     * @param _scene 场景
     */
    void init(Scene* _scene);

    /**
     * 初始化场景
     */
    void initScene();


    /**初始化imGUI*/
    void initImGUI();


    /**
     * 执行渲染流程
     */
    void renderLoop();

    /**
     * 渲染场景
     */
    void renderScene(float elapsedTime);

    /**渲染imGUI*/
    void renderImGUI(float elapsedTime);

    /**
     * 关闭，释放内存
     */
    void terminate();

public:
    BaseGui* sceneUi;
public:

    /**
     * 获得实例
     * @return MRenderer单例对象
     */
    static MRenderer *getInstance(const String title = Config::WINDOW_TITLE, const int width = Config::WINDOW_WIDTH, const int height = Config::WINDOW_HEIGHT);

    /**
     * 渲染场景
     * @param p_scene
     */
    void render(Scene *p_scene);
};


#endif //MRenderer_MRenderer_H
